/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class EvaluacionDAOImpl implements orm.dao.EvaluacionDAO {
	private static final org.apache.log4j.Logger _logger = org.apache.log4j.Logger.getLogger(EvaluacionDAOImpl.class);
	public Evaluacion loadEvaluacionByORMID(int ev_id) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return loadEvaluacionByORMID(session, ev_id);
		}
		catch (Exception e) {
			_logger.error("loadEvaluacionByORMID(int ev_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion getEvaluacionByORMID(int ev_id) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return getEvaluacionByORMID(session, ev_id);
		}
		catch (Exception e) {
			_logger.error("getEvaluacionByORMID(int ev_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion loadEvaluacionByORMID(int ev_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return loadEvaluacionByORMID(session, ev_id, lockMode);
		}
		catch (Exception e) {
			_logger.error("loadEvaluacionByORMID(int ev_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion getEvaluacionByORMID(int ev_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return getEvaluacionByORMID(session, ev_id, lockMode);
		}
		catch (Exception e) {
			_logger.error("getEvaluacionByORMID(int ev_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion loadEvaluacionByORMID(PersistentSession session, int ev_id) throws PersistentException {
		try {
			return (Evaluacion) session.load(orm.Evaluacion.class, new Integer(ev_id));
		}
		catch (Exception e) {
			_logger.error("loadEvaluacionByORMID(PersistentSession session, int ev_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion getEvaluacionByORMID(PersistentSession session, int ev_id) throws PersistentException {
		try {
			return (Evaluacion) session.get(orm.Evaluacion.class, new Integer(ev_id));
		}
		catch (Exception e) {
			_logger.error("getEvaluacionByORMID(PersistentSession session, int ev_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion loadEvaluacionByORMID(PersistentSession session, int ev_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Evaluacion) session.load(orm.Evaluacion.class, new Integer(ev_id), lockMode);
		}
		catch (Exception e) {
			_logger.error("loadEvaluacionByORMID(PersistentSession session, int ev_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion getEvaluacionByORMID(PersistentSession session, int ev_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Evaluacion) session.get(orm.Evaluacion.class, new Integer(ev_id), lockMode);
		}
		catch (Exception e) {
			_logger.error("getEvaluacionByORMID(PersistentSession session, int ev_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion[] listEvaluacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return listEvaluacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("listEvaluacionByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion[] listEvaluacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return listEvaluacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("listEvaluacionByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion[] listEvaluacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Evaluacion as Evaluacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Evaluacion[]) list.toArray(new Evaluacion[list.size()]);
		}
		catch (Exception e) {
			_logger.error("listEvaluacionByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion[] listEvaluacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Evaluacion as Evaluacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Evaluacion[]) list.toArray(new Evaluacion[list.size()]);
		}
		catch (Exception e) {
			_logger.error("listEvaluacionByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion loadEvaluacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return loadEvaluacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("loadEvaluacionByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion loadEvaluacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return loadEvaluacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("loadEvaluacionByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion loadEvaluacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Evaluacion[] evaluacions = listEvaluacionByQuery(session, condition, orderBy);
		if (evaluacions != null && evaluacions.length > 0)
			return evaluacions[0];
		else
			return null;
	}
	
	public Evaluacion loadEvaluacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Evaluacion[] evaluacions = listEvaluacionByQuery(session, condition, orderBy, lockMode);
		if (evaluacions != null && evaluacions.length > 0)
			return evaluacions[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateEvaluacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return iterateEvaluacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("iterateEvaluacionByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateEvaluacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return iterateEvaluacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("iterateEvaluacionByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateEvaluacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Evaluacion as Evaluacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			_logger.error("iterateEvaluacionByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateEvaluacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Evaluacion as Evaluacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			_logger.error("iterateEvaluacionByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion createEvaluacion() {
		return new orm.Evaluacion();
	}
	
	public boolean save(orm.Evaluacion evaluacion) throws PersistentException {
		try {
			orm.EvaluacionDocentePersistentManager.instance().saveObject(evaluacion);
			return true;
		}
		catch (Exception e) {
			_logger.error("save(orm.Evaluacion evaluacion)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Evaluacion evaluacion) throws PersistentException {
		try {
			orm.EvaluacionDocentePersistentManager.instance().deleteObject(evaluacion);
			return true;
		}
		catch (Exception e) {
			_logger.error("delete(orm.Evaluacion evaluacion)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Evaluacion evaluacion)throws PersistentException {
		try {
			if(evaluacion.getRegionre_numeroregion() != null) {
				evaluacion.getRegionre_numeroregion().evaluacion.remove(evaluacion);
			}
			
			return delete(evaluacion);
		}
		catch(Exception e) {
			_logger.error("deleteAndDissociate()", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Evaluacion evaluacion, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(evaluacion.getRegionre_numeroregion() != null) {
				evaluacion.getRegionre_numeroregion().evaluacion.remove(evaluacion);
			}
			
			try {
				session.delete(evaluacion);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			_logger.error("deleteAndDissociate()", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Evaluacion evaluacion) throws PersistentException {
		try {
			orm.EvaluacionDocentePersistentManager.instance().getSession().refresh(evaluacion);
			return true;
		}
		catch (Exception e) {
			_logger.error("refresh(orm.Evaluacion evaluacion)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Evaluacion evaluacion) throws PersistentException {
		try {
			orm.EvaluacionDocentePersistentManager.instance().getSession().evict(evaluacion);
			return true;
		}
		catch (Exception e) {
			_logger.error("evict(orm.Evaluacion evaluacion)", e);
			throw new PersistentException(e);
		}
	}
	
	public Evaluacion loadEvaluacionByCriteria(EvaluacionCriteria evaluacionCriteria) {
		Evaluacion[] evaluacions = listEvaluacionByCriteria(evaluacionCriteria);
		if(evaluacions == null || evaluacions.length == 0) {
			return null;
		}
		return evaluacions[0];
	}
	
	public Evaluacion[] listEvaluacionByCriteria(EvaluacionCriteria evaluacionCriteria) {
		return evaluacionCriteria.listEvaluacion();
	}
}
